<template>
  <el-container>
    <el-header>
      <el-button @click="$router.push('/')">返回首页</el-button>
    </el-header>
    <el-main>
      <el-row :gutter="20">
        <el-col :span="16">
          <el-timeline>
            <el-timeline-item
              v-for="item in archives"
              :key="item.id"
              :timestamp="item.create_time"
            >
              <router-link
                :to="{ name: 'ArticleDetail', params: { id: item.id } }"
              >
                {{ item.title }}
              </router-link>
            </el-timeline-item>
          </el-timeline>
        </el-col>
        <el-col :span="8">
          <Sidebar />
        </el-col>
      </el-row>
    </el-main>
  </el-container>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import Sidebar from '../components/Sidebar.vue'
import api from '../api'

const archives = ref([])

onMounted(async () => {
  const res = await api.get('/articles')
  archives.value = res.data.result.data
})
</script>
